package ericXie.com.command 
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import ericXie.com.component.PopUpWindowMovieClip;
	import ericXie.com.events.PopUpWindowEvent;
	import ericXie.com.events.SimpleButtonAshyEvent;
	import ericXie.com.model.MainModel;
	/**
	 * ...弹出提示窗和关闭提示框
	 * @author ErciXie
	 */
	public class PopUpWindowCommand implements ICommand 
	{
		private var _model:MainModel=MainModel.getInstance();
		private var _popWindow:PopUpWindowMovieClip;
		public function PopUpWindowCommand() 
		{
			
		}
		
		public function execute(event:CairngormEvent):void 
		{
			var evt:PopUpWindowEvent = event as PopUpWindowEvent;
			if (evt.popUpType == PopUpWindowEvent.POPUP_TYPE)
			{
				popUpHandler();
			}else if (evt.popUpType == PopUpWindowEvent.POPDOWN_TYPE)
			{
				popDownHandler();
			}
		}
		//关闭提示框
		private function popDownHandler():void 
		{
			if (_model.popupWindow != null) {
				if (_model.mainApp.contains(_model.popupWindow)) {
					_model.mainApp.removeChild(_model.popupWindow)
					_model.popupWindow = null;
					_model.roulette.rotateSpeed = 1;/*设置转盘默认旋转速度恢复为1*/
					_model.roulette.autoRotation = false;/*设置是否自动旋转为否*/
					_model.halo.startRoulette = true;/*设置中心旋转部分回到初始状态*/
					new SimpleButtonAshyEvent(_model.startBn, true).dispatch();/*设置开始抽奖按钮为可点击状态*/
				}
			}
			
		}
		
		private function popUpHandler():void 
		{
			_popWindow = new PopUpWindowMovieClip();
			_model.mainApp.addChild(_popWindow);
			_model.popupWindow = _popWindow;
			_popWindow.x = (_model.mainApp.stage.stageWidth - _popWindow.width) / 2;
			_popWindow.y = (_model.mainApp.stage.stageHeight - _popWindow.height) / 2;
			if (_model.getData != null) {
				/*如果没有抽奖机会*/
				if (Number(_model.getData[0]) == 0) {
					_popWindow.titleText = "对不起您的抽奖机会已经用完,感谢您的参与";
					_popWindow.contentText = "";
					_popWindow.linkText = "";
				}else {
					/*没有中奖的提示*/
					if (Number(_model.getData[1]) == 9) {
						_popWindow.titleText = "对不起您没有中奖";
						var residueNum:Number = Number(_model.getData[0]) - 1;
						/*剩余抽奖机会的提示*/
						if (residueNum > 0) {
							_popWindow.contentText = "您还有"+residueNum+"次机会,再接再厉";
						}else {
							_popWindow.contentText = "您的抽奖机会已经用完";
						}
						_popWindow.linkText = "";
					}else {
						/*中奖的提示，并且有中奖的超级链接*/
						_popWindow.titleText = "恭喜您获得";
						_popWindow.contentText = _model.getData[2];
						_popWindow.linkText = "<a href='javaScript:award(" + Number(_model.getData[1])+ ")' target='_self'>查看我的礼品</a>";
					}
				}
			}else {
			/*	完全没有抽奖机会的时候，或者没有填写信息的*/
				_popWindow.titleText = "对不起您的抽奖机会已经用完，或者您没有填写完成注册信息。请核实后在抽奖";
					_popWindow.contentText = "";
					_popWindow.linkText = "";
			}
			
			
		}
		
	}

}